
(** 
    For instructions that take a long time to execute,
    it is sometimes helpful to use a cache to store
    computed values.  This is not intended as a system
    for memoization, but rather for informal value storage.
    
    An example of its use is in the long interval arithmetic
    calculations of the Kepler Conjecture.  We marshall the
    resulting values in a file so that they do not need to
    be repeated.
 *) 


(** 
    A simple API to lookup, add, and remove elements
    from a cache.  
 *)
module type T =
sig

  module Key : Eqtype.T

  type 'a cache

  val lookup : 'a cache -> Key.t -> 'a option
    (** Returns [None] if the element isn't found. *)

  val cache : 'a cache -> Key.t -> 'a -> unit
    (** Cache a key/value pair *)

  val clear : 'a cache -> unit
    (** Empty the cache. *) 
    
  val remove : 'a cache -> Key.t -> unit
    (** Remove an element from the cache. *) 

  val save : 'a cache -> string -> unit
    (** Write the contents of the cache to disk. *)

  val load : string -> 'a cache
    (** Load the contents of a saved cache into memory. *) 
    
end


module S(Key : Eqtype.T) : T with module Key = Key
